#!/usr/bin/perl
#2003 IBM_PROLOG_BEGIN_TAG 
#2003 This is an automatically generated prolog. 
#2003  
#2003 r53a.hsc src/hsc/scripts/hdwr_svr_helper.sh 1.3 
#2003  
#2003 IBM CONFIDENTIAL 
#2003  
#2003 OBJECT CODE ONLY SOURCE MATERIALS 
#2003  
#2003 (C) COPYRIGHT International Business Machines Corp. 2003,2004 
#2003 All Rights Reserved 
#2003  
#2003 The source code for this program is not published or otherwise 
#2003 divested of its trade secrets, irrespective of what has been 
#2003 deposited with the U.S. Copyright Office. 
#2003  
#2003 IBM_PROLOG_END_TAG 

# http://vergil.chemistry.gatech.edu/resources/programming/perl-tutorial/process.html
# This script will try to bring up a slip interface given 
#  a vtty and optional IP address information
print "args = ".@ARGV."\n";
if (@ARGV < 3) {
   print "Usage: hdwr_svr_helper slipup ttypath network_interface netmask\n";
   print "   Ex: hdwr_svr_helper slipup /dev/pts/1 192.168.1.1 255.255.255.0\n";
   die("exiting...");
}

if (@ARGV[0] != "slipup") {
  die ("bad command type");
}

$tty_path = @ARGV[1];
$gateway_address =  @ARGV[2];
$ifconfig_netmask = @ARGV[3];

print "tty path = ".$tty_path."\n";
print "gateway_address = ".$gateway_address."\n";
print "netmask = ".$ifconfig_netmask."\n";

$slattachout = `/sbin/slattach -ed -p slip $tty_path`;
print "slattach output:\n\n".$slattachout."\n";

$slip_interface = "uninitialized";

$ind = index($slattachout, " interface sl");
print "slindex = $ind \n";
if ($ind > 0) {
  $slip_interface = substr($slattachout, $ind + 11, 3);
} else {
  print "slattach output error:\n\n".$slattachout."\n";
  die("slattach output error");
}

print "slipifc = '$slip_interface' \n";
print "slipifc len = ".length($slip_interface)."\n";

# mtu should not exceed the phyp max of 576
$ifcfgout = `/sbin/ifconfig $slip_interface $gateway_address mtu 296 netmask $ifconfig_netmask up`;

print "ifconfig output:\n\n";
print $ifcfgout;
print "\n\ndone.\n\n"
